JavaScript Testing with Jasmine by Evan Hahn
Author: Evan Hahn , Date: March 26, 2014
, Views: 311
expect(8).toBeGreaterThan(5); expect(5).toBeLessThan(12); expect("a").toBeLessThan("z"); // Notice that it works for strings too!
Not too difficult!
Nearness: toBeCloseTo
toBeCloseTo allows you to check if a number is close to another number, given a certain amount of decimal precision as the second argument.
If you want to make sure that a variable is close to 12.3 within one decimal point, you’d code it like this:
expect(12.34).toBeCloseTo(12.3, 1); // success
If you want it to be the same within two decimal points, you’d change the 1 to a 2. This spec will fail, though—they differ at the second decimal digit:
Copyright Disclaimer:
This site does not store any files on its server. We only index and link
to content provided by other sites. Please contact the content providers
to delete copyright contents if any and email us, we'll remove relevant
links or contents immediately.